﻿using MediatR;
using W.Purchase.API.Application.Command;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler
{
    public class VendorDeleteCommandHandler : IRequestHandler<VendorDeleteCommand, int>
    {
        private readonly IVendorRepository vendorRepository;

        public VendorDeleteCommandHandler(IVendorRepository vendorRepository)
        {
            this.vendorRepository = vendorRepository;
        }

        public async Task<int> Handle(VendorDeleteCommand request, CancellationToken cancellationToken)
        {
            var list = await vendorRepository.GetAsync(w=>w.VendorId==request.VendorId);
            list.FirstOrDefault().IsDelete=true;
            list.FirstOrDefault().DeleteTime=DateTime.Now;
            return await vendorRepository.Update(list.FirstOrDefault());
        }
    }
}
